<%!
_type_def={
"i32":"int32_t",
"ui32":"uint32_t",
"i64":"int64_t",
"ui64":"uint64_t",
"string":"std::string",
"float":"float",
"double":"double",
"char":"int8_t",
}
_sqlfmt_def={
"i32":"%d",
"ui32":"%d",
"i64":"%ll",
"ui64":"%llu",
"string":"'%s'",
"float":"%f",
"double":"%f",
"char":"%d",
}
_getField_def={
"i32":"GetField_Int",
"ui32":"GetField_Int",
"i64":"GetField_Long",
"ui64":"GetField_Long",
"string":"GetField_String",
"float":"GetField_Float",
"double":"GetField_Float",
"char":"GetField_Int",
}
def _type(t):
	if _type_def.has_key(t) :
		return _type_def[t]
	else:
		return "UNKNOWN"

def _sqlfmt(t):
	if _sqlfmt_def.has_key(t) :
		return _sqlfmt_def[t]
	else:
		return "UNKNOWN"

def _getField(t):
	if _getField_def.has_key(t) :
		return _getField_def[t]
	else:
		return "UNKNOWN"

def _pks(cols):
	res = {} 
	for col_name, col in cols.items():
		if col.Extra.has_key('key') : res[col_name] = col
	return res

def _n_pks(cols):
	res = {} 
	for col_name, col in cols.items():
		if col.Extra.has_key('key') and ""!=col.Extra['key'] : continue
		else: 
			res[col_name] = col
	return res

def _cols_2_params(cols):
	res = ''
	for col_name, col in cols.items():
		res += " %s %s," % ( _type(col.Type), col.getFixName() )
	return res.strip().rstrip(',')

def _cols_2_sqlparams(cols):
	res = ''
	for col_name, col in cols.items():
		res += " %s=%s," % ( col.Name, _sqlfmt(col.Type) )
	return res.strip().rstrip(',')
	
%>
<%def name="_class(name)" >${name.replace('.','_').capitalize()}</%def>
<%def name="_macro(name)" >${name.replace('.','_').upper()}</%def>
<%def name="_struct_field(col)" >${_type(col.Type)} ${col.getFixName()}</%def>
<%def name="_get_field(col)" >${_getField(col.Type)}("${col.Name}")</%def>
<%def name="_pks_params(cols)" >${_cols_2_params( _pks(cols) )}</%def>
<%def name="_n_pks_params(cols)" >${_cols_2_params( _n_pks(cols) )}</%def>
<%def name="_pks_sqlparams(cols)" >${_cols_2_sqlparams( _pks(cols) )}</%def>
<%def name="_n_pks_sqlparams(cols)" >${_cols_2_sqlparams( _n_pks(cols) )}</%def>

